/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package editor.templates;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author RoderickNestor
 */
public class Test {
    
    public String readStream(String path) {
        Reader reader = null;
        try {
            InputStream is = this.getClass().getResourceAsStream(path);
            if (is != null) {
                try {
                    reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
                } catch (Exception e) {
                    System.out.println(e.toString() + "111111");
                }
            }
        } catch (Exception e) {
            System.out.println(e.toString() + "222222");
        }
        String file = readFileAsString(reader);
        return file;
    }
    
    protected static String readFileAsString(Reader reader) {
        StringBuffer fileData = new StringBuffer(100000);
        char[] buf = new char[1024];
        int numRead = 0;
        try {
            while ((numRead = reader.read(buf)) != -1) {
                String readData = String.valueOf(buf, 0, numRead);
                fileData.append(readData);
                buf = new char[1024];
            }
            reader.close();
        } catch (IOException ex) {
            System.out.println(ex.toString());
        }
        return fileData.toString();
    }

    protected void createfile(String Name, String path, String Contenido) {
        Writer output = null;
        System.out.println(path + File.separator + Name);
        File file = new File(path + File.separator + Name);
        try {
            output = new BufferedWriter(new FileWriter(file));
            output.write(Contenido);
            output.close();
        } catch (IOException ex) {
            System.out.println(ex.toString());
        }
    }

    public static void main(String[] args) {
        Test t = new Test();
        
        System.out.println(t.readStream("/editor/app.config"));
        
        
    }
}
